$(document).ready(function () {
});

//自定义登入业务操作对象
window.userregister = (function () {

    var obj = {};
    var msg = "请正确的填写登录表单信息！";
    //处理用户登录操作
    obj.register = function () {

        if (obj.valid()) {
            var url = $("#register").attr("data-href");
            var data = {
                name: $("#name").val(),
                //registerPasswd : MD5($("#registerPasswd").val()),
                phoneno : $("#phoneno").val(),
                password: $("#password").val(),
                email: $("#email").val(),
                username: $("#username").val(),
                confirm: $("#confirm").val()
            };
            $.post(url, data, function (json) {
                if (json.success) {
                    window.modal.message("提示", json.message);
                    $("#doit").on("click", function () {
                        window.location.href = json.datas;
                    });

                } else {
                    window.modal.message("提示", json.message);
                }
            }, "json");
        } else {
            window.modal.message("提示", msg);
        }
    };

    //登入简单验证
    obj.valid = function () {
        var flag = true;
        $("#registerForm :input").each(function () {

            if ($(this).val() == "") {
                flag = false;
                msg = "输入项不能为空！";
                return false;
            }
        });
        if ($('input[id=password]').val() != $('input[id=confirm]').val()) {
            flag = false;
            msg = "两次输入的密码不一致！";
            return false;
        }
        return flag;
    };

    return obj;
})();
$("#register").on("click", function () {
    window.userregister.register();
});

//自定义通用提示消息模态框
window.modal = (function () {
    var obj = {};
    obj.message = function (title, msg) {
        $('#myModal').on('show.bs.modal', function () {
            var modal = $(this);
            modal.find('.modal-title').html(title);
            modal.find('.modal-body').html(msg);
        });
        $('#myModal').modal({backdrop: 'static', keyboard: false});
    };
    return obj;
})();
